import os
import json

def load_config():
    errorMsg = None
    config_path = os.path.join(os.getcwd(), "config.json")
    def_config = {
            "baudrate": 15000000,
            "web_link": "",
            "auto_open": True,
            "yx_flow": [
                {
                    "dsc": "选择文件",
                    "type": "file",
                    "action": "select",
                    "value": "",
                    "xpath": ""
                }
            ]
        }
    if not os.path.exists(config_path):
        with open(config_path, "w", encoding="utf-8") as f:
            json.dump(def_config, f, indent=4, ensure_ascii=False)
        return def_config, errorMsg

    try:
        with open(config_path, "r", encoding="utf-8") as f:
            config = json.load(f)
            return config, errorMsg
    except Exception as e:
        print(f"{e}")
        errorMsg = f"❌ load 配置文件失败 {e}"
    
    return def_config, errorMsg
        

